package cn.itsource.pay.service.impl;

import cn.itsource.basic.service.impl.BaseServiceImpl;
import cn.itsource.pay.contants.PayContants;
import cn.itsource.pay.domain.AliPayInfo;
import cn.itsource.pay.domain.PayBill;
import cn.itsource.pay.mapper.AliPayInfoMapper;
import cn.itsource.pay.mapper.PayBillMapper;
import cn.itsource.pay.service.IPayBillService;
import cn.itsource.pay.utils.AliPayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PayBillServiceImpl extends BaseServiceImpl<PayBill> implements IPayBillService {

    @Autowired
    private AliPayInfoMapper aliPayInfoMapper;

    @Autowired
    private PayBillMapper payBillMapper;
    /*
        1.支付方式


     */
    @Override
    public String pay(PayBill payBill) {
        //根据用户选择的支付类型，调用不同的支付渠道
        switch (payBill.getPayChannel()){
            case PayContants.ALIPAY:
                AliPayInfo aliPayInfo = aliPayInfoMapper.loadById(1L);
                //支付宝支付
                String result = AliPayUtils.aliPay(payBill, aliPayInfo);

                return  result;
            case PayContants.WXPAY:
                //微信支付
                return  "";
            case PayContants.UNIONPAY:
                //银联支付
                break;

        }

        return "";
    }

    @Override
    public PayBill queryByOrderSn(String orderSn) {
        return payBillMapper.queryByOrderSn(orderSn);
    }
}
